﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace PLCSimulator
{
    public class ButtonControl : Button
    {
        public Action<string, bool>? ButtonStateChanged { get; set; }

        public ButtonControl() : base()
        {
            //this.ButtonStateChanged = null;
        }

        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            if (this.ButtonStateChanged != null)
            {
                base.OnMouseDown(e);
            }
        }
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            if (this.ButtonStateChanged != null)
            {
                base.OnMouseUp(e);
            }
        }
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (this.ButtonStateChanged != null)
            {
                base.OnMouseLeftButtonDown(e);
            }
        }
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            if (this.ButtonStateChanged != null)
            {
                base.OnMouseLeftButtonUp(e);
            }
        }
        protected override void OnIsPressedChanged(DependencyPropertyChangedEventArgs e)
        {
            Action<string, bool>? action = this.ButtonStateChanged;
            if (action != null)
            {
                base.OnIsPressedChanged(e);

                action((string)this.DataContext, this.IsPressed);
            }
        }
    }
}
